library(foreign)
library(sandwich)
library(lmtest)
library(apsrtable)
library(plyr)

d<-read.csv("survey1_updateddemos.csv")
d <- d[d$Q1.12 !="",]

names(d)

table(d$Q1.17)
d$vote16<-NA
d$vote16[d$Q1.17=="Donald Trump"]<-"trump"
d$vote16[d$Q1.17=="Hillary Clinton"]<-"clinton"
d$vote16[d$Q1.17=="I would not vote"]<-"novote"
d$vote16[d$Q1.17=="Someone else"]<-"other"
table(d$vote16)


##gender
table(d$Q1.3)
d$female[d$Q1.3=="Female"]<-1
d$female[d$Q1.3=="Male"]<-0
table(d$female)


#race
table(d$Q1.5)
d$white<-I(d$Q1.5=="White")
table(d$white)
d$black<-I(d$Q1.5=="Black")
table(d$black)


#hispanic
table(d$Q1.6)
d$latino<-I(d$Q1.6=="Yes")
table(d$latino)


##nhwhite
d$nhwhite<-I(d$white==T & d$latino==F)
table(d$nhwhite)
#nhblack
d$nhblack<-I(d$black==T & d$latino==F)
table(d$nhblack)
dim(d)


##Individual-Level Issue Positions
d$raise.corporate.tax <- as.numeric(as.character(mapvalues(x=d$Q2.2,from=c('should not raise corporate income taxes','should raise corporate income taxes'),to=c(0,1))))
d$prohibit.muslim.immigration <- as.numeric(as.character(mapvalues(x=d$Q2.3,from=c('should not prohibit Muslim immigration','should prohibit Muslim immigration'),to=c(0,1))))
d$repeal.obamacare <- as.numeric(as.character(mapvalues(x=d$Q2.4,from=c('should not repeal Obamacare','should repeal Obamacare'),to=c(0,1))))
d$birth.control.coverage <- as.numeric(as.character(mapvalues(x=d$Q81,from=c('should not require insurance to cover birth control','should require insurance to cover birth control'),to=c(0,1))))
d$deport.illegal <- as.numeric(as.character(mapvalues(x=d$Q2.8,from=c('should deport all illegal immigrants','should not deport all illegal immigrants'),to=c(1,0))))
d$citizenship.path <- as.numeric(as.character(mapvalues(x=d$Q2.9,from=c('should not create a path to citizenship for illegal immigrants','should create a path to citizenship for illegal immigrants'),to=c(0,1))))

#EP Note - Peple at 0/0 or 1/1 can't be mapped to candidate positions about 25 percent of respondents
table(d$deport.illegal,d$citizenship.path)

table(d$Q3.2)
#Individual-Level Issue Importance
d$raise.corporate.tax.high.salience <- as.numeric(as.character(mapvalues(x=as.character(d$Q3.2), from=c('Extremely important','Very important','Moderately important','Not that important','No opinion',''),to=c(1,1,0,0,0,NA))))
d$prohibit.muslim.immigration.high.salience <- as.numeric(as.character(mapvalues(x=as.character(d$Q3.3), from=c('Extremely important','Very important','Moderately important','Not that important','No opinion',''),to=c(1,1,0,0,0,NA))))
d$birth.control.coverage.high.salience <- as.numeric(as.character(mapvalues(x=as.character(d$Q3.9), from=c('Extremely important','Very important','Moderately important','Not that important','No opinion',''),to=c(1,1,0,0,0,NA))))
d$repeal.obamacare.high.salience <- as.numeric(as.character(mapvalues(x=as.character(d$Q3.4), from=c('Extremely important','Very important','Moderately important','Not that important','No opinion',''),to=c(1,1,0,0,0,NA))))
d$citizenship.path.high.salience <- as.numeric(as.character(mapvalues(x=as.character(d$Q3.10), from=c('Extremely important','Very important','Moderately important','Not that important','No opinion',''),to=c(1,1,0,0,0,NA)))) 
d$number.high.salience.issue <- d$raise.corporate.tax.high.salience + d$prohibit.muslim.immigration.high.salience + d$birth.control.coverage.high.salience  + d$repeal.obamacare.high.salience + d$citizenship.path.high.salience
d$number.high.salience.agree.issue <- d$raise.corporate.tax.high.salience + d$prohibit.muslim.immigration.high.salience + d$birth.control.coverage.high.salience  + d$repeal.obamacare.high.salience

##conjoint analysis

d$dup<-duplicated(d$psid)
table(d$dup)
d<-subset(d, d$dup==F)
dim(d)
unique(table(d$psid))##14 observations for each respondent (7 profiles * 2 candidates)

head(d$ResponseID)
d$respondent<-as.character(d$psid)
unique(table(d$psid))


d2<-read.csv("study1_long.csv",header=T)

head(d2$respondent)
d2$respondent<-as.character(d2$respondent)
length(unique(d2$respondent))
table(d$respondent%in%d2$respondent)


head(d2)
dim(d2)
unique(table(d2$respondentIndex))##14 observations for each respondent (7 profiles * 2 candidates)
dim(d2)
dim(d)
d3<-merge(d2, d[,c("nhwhite","nhblack","latino","female","vote16","respondent",'raise.corporate.tax','prohibit.muslim.immigration','repeal.obamacare','birth.control.coverage','deport.illegal','citizenship.path','raise.corporate.tax.high.salience','prohibit.muslim.immigration.high.salience','repeal.obamacare.high.salience','birth.control.coverage.high.salience','citizenship.path.high.salience','number.high.salience.issue','number.high.salience.agree.issue','ResponseId')], by.x="respondent", all.x=T)
head(d3)

d3<-subset(d3, !is.na(d3$respondent) & !is.na(d3$selected))
dim(d3)


d<-d3
head(d)
unique(table(d$respondentIndex))##14 observations for each respondent (7 profiles * 2 candidates)
unique(table(d$respondent))##14 observations for each respondent (7 profiles * 2 candidates)
table(d$respondent)[table(d$respondent)==392]


####
#Code Up Issue Importance
####

##Individual-Level Issue Salience
#d$raise.corporate.tax.high.salience <- ifelse(d$econ.imp > 2, 1, 0)
#d$prohibit.muslim.immigration.high.salience <- ifelse(d$terror.imp > 2, 1, 0)
#d$birth.control.coverage.high.salience <- ifelse(d$women.imp > 2, 1, 0)
#d$repeal.obamacare.high.salience <- ifelse(d$health.imp > 2, 1, 0)
#d$citizenship.path.high.salience <- ifelse(d$imm.imp > 2, 1, 0)

mean(d$econ.imp, na.rm=TRUE)
mean(d$terror.imp, na.rm=TRUE)
mean(d$women.imp, na.rm=TRUE)
mean(d$health.imp, na.rm=TRUE)
mean(d$imm.imp, na.rm=TRUE)

mean(d$imm.imp+d$econ.imp+d$terror.imp+d$women.imp+d$health.imp, na.rm=TRUE)/5



####
#Code Up Candidate-Level Issue Positions
####

d$raise.corporate.tax.candidate <- as.numeric(as.character(mapvalues(x=d$The.economy,from=c('Lower corporate income taxes','Raise corporate income taxes'),to=c(0,1))))
d$prohibit.muslim.immigration.candidate <- as.numeric(as.character(mapvalues(x=d$Terrorism,from=c('No religious immigration controls','Prohibit Muslim immigration'),to=c(0,1))))
d$repeal.obamacare.candidate <- as.numeric(as.character(mapvalues(x=d$Healthcare,from=c('Support Obamacare','Repeal Obamacare'),to=c(0,1))))
d$birth.control.coverage.candidate <- as.numeric(as.character(mapvalues(x=d$Women.s.equality,from=c('Do not require insurance to cover birth control','Require insurance to cover birth control'),to=c(0,1))))
d$deport.illegal.candidate <- as.numeric(as.character(mapvalues(x=d$Illegal.immigration,from=c('Deportation of all illegal immigrants','Path to citizenship for illegal immigrants'),to=c(1,0))))

d$tax.reputation.consistent <- NA
d$tax.reputation.consistent[d$raise.corporate.tax.candidate==0 & d$Political.Party=='Republican'] <- 1
d$tax.reputation.consistent[d$raise.corporate.tax.candidate==1 & d$Political.Party=='Democrat'] <- 1
d$tax.reputation.consistent[d$raise.corporate.tax.candidate==1 & d$Political.Party=='Republican'] <- 0
d$tax.reputation.consistent[d$raise.corporate.tax.candidate==0 & d$Political.Party=='Democrat'] <- 0

d$muslim.reputation.consistent <- NA
d$muslim.reputation.consistent[d$prohibit.muslim.immigration.candidate==1 & d$Political.Party=='Republican'] <- 1
d$muslim.reputation.consistent[d$prohibit.muslim.immigration.candidate==0 & d$Political.Party=='Democrat'] <- 1
d$muslim.reputation.consistent[d$prohibit.muslim.immigration.candidate==0 & d$Political.Party=='Republican'] <- 0
d$muslim.reputation.consistent[d$prohibit.muslim.immigration.candidate==1 & d$Political.Party=='Democrat'] <- 0

d$obamacare.reputation.consistent <- NA
d$obamacare.reputation.consistent[d$repeal.obamacare.candidate==1 & d$Political.Party=='Republican'] <- 1
d$obamacare.reputation.consistent[d$repeal.obamacare.candidate==0 & d$Political.Party=='Democrat'] <- 1
d$obamacare.reputation.consistent[d$repeal.obamacare.candidate==0 & d$Political.Party=='Republican'] <- 0
d$obamacare.reputation.consistent[d$repeal.obamacare.candidate==1 & d$Political.Party=='Democrat'] <- 0

d$birthcontrol.reputation.consistent <- NA
d$birthcontrol.reputation.consistent[d$birth.control.coverage.candidate==1 & d$Political.Party=='Republican'] <- 1
d$birthcontrol.reputation.consistent[d$birth.control.coverage.candidate==0 & d$Political.Party=='Democrat'] <- 1
d$birthcontrol.reputation.consistent[d$birth.control.coverage.candidate==0 & d$Political.Party=='Republican'] <- 0
d$birthcontrol.reputation.consistent[d$birth.control.coverage.candidate==1 & d$Political.Party=='Democrat'] <- 0

d$immigration.reputation.consistent <- NA
d$immigration.reputation.consistent[d$deport.illegal.candidate==1 & d$Political.Party=='Republican'] <- 1
d$immigration.reputation.consistent[d$deport.illegal.candidate==0 & d$Political.Party=='Democrat'] <- 1
d$immigration.reputation.consistent[d$deport.illegal.candidate==0 & d$Political.Party=='Republican'] <- 0
d$immigration.reputation.consistent[d$deport.illegal.candidate==1 & d$Political.Party=='Democrat'] <- 0

####
#Alignment Between Candidate and Individual Characteristics
####
d$corporate.tax.agree <- ifelse(d$raise.corporate.tax==d$raise.corporate.tax.candidate, 1, 0)
d$muslim.immigration.agree <- ifelse(d$prohibit.muslim.immigration==d$prohibit.muslim.immigration.candidate,1,0)
d$obamacare.agree <- ifelse(d$repeal.obamacare==d$repeal.obamacare.candidate,1,0)
d$birth.control.agree <- ifelse(d$birth.control.coverage==d$birth.control.coverage.candidate,1,0)
d$copartisan <- NA
d$copartisan[which(d$dem==1 & d$Political.Party=='Democrat')] <- 1
d$copartisan[which(d$dem==0 & d$Political.Party=='Republican')] <- 1

d$copartisan[which(d$dem==1 & d$Political.Party=='Republican')] <- 0
d$copartisan[which(d$dem==0 & d$Political.Party=='Democrat')] <- 0
d$number.agreements <- d$corporate.tax.agree + d$muslim.immigration.agree + d$obamacare.agree + d$birth.control.agree
d$number.disagreements <- 4 - d$number.agreements
dim(d)


###
#Determining Profile Pairs with candidates from opposing parties


###
race.type <- d[,c('respondent','respondentIndex','task','profile','Political.Party','number.agreements')]
profile.1s <- subset(race.type,race.type$profile==1)
names(profile.1s) <- c('respondent','respondentIndex','task','profile','party.1','number.agreements.1')
profile.1s$profile <- NULL
profile.1s <- unique(profile.1s[,names(profile.1s)])

profile.2s <- subset(race.type,race.type$profile==2)
names(profile.2s) <- c('respondent','respondentIndex','task','profile','party.2','number.agreements.2')
profile.2s$profile <- NULL
profile.2s <- unique(profile.2s[,names(profile.2s)])

race.type <- merge(profile.1s,profile.2s,by=c('respondent','respondentIndex','task'))
race.type$opposing.parties <- ifelse(race.type$party.1==race.type$party.2,0,1)
race.type$party.1 <- NULL
race.type$party.2 <- NULL


d$number.consistent <- d$tax.reputation.consistent + d$muslim.reputation.consistent + d$obamacare.reputation.consistent + d$birthcontrol.reputation.consistent + d$immigration.reputation.consistent

dim(d)
d <- merge(d,race.type,by=c('respondent','respondentIndex','task'),all.x=TRUE)
dim(d)

#Checking Conjoint Information
conjoint.sum <- ddply(d,.(respondent,respondentIndex,dem),summarise,total.count=length(respondent),profile.count=total.count/2,opposing.party.profiles=sum(opposing.parties),opposing.party.tasks=opposing.party.profiles/2)
conjoint.sum <- conjoint.sum[order(conjoint.sum$total.count,decreasing=TRUE),]

#There are 3073 respondents (unique combinations of respondent and respondentIndex), they each saw 14 profiles
dim(conjoint.sum)
length(conjoint.sum$respondent[which(conjoint.sum$total.count > 14)])
length(conjoint.sum$respondent[which(conjoint.sum$total.count==14)])


fit.w.robust <- function(model, cluster.var, dta){	
	robust.se <- function(model, cluster){
		require(sandwich)
		require(lmtest)
		M <- length(unique(cluster))
		N <- length(cluster)
		K <- model$rank
		dfc <- (M/(M - 1)) * ((N - 1)/(N - K))
		uj <- apply(estfun(model), 2, function(x) tapply(x, cluster, sum));
		rcse.cov <- dfc * sandwich(model, meat = crossprod(uj)/N)
		rcse.se <- coeftest(model, rcse.cov)
		return(list(rcse.cov, rcse.se))
	}
	
	out <- model$model
	clustervar <- mapply(paste,cluster.var,dta[!(1:dim(dta)[1] %in% model$na.action),cluster.var],sep="")
	vcov <- robust.se(model, clustervar)
	model$se <- vcov[[1]]
	model$coeftest <- vcov[[2]]
	return(model)
}

d.frame <- d
d.frame$respondent <- factor(paste(d.frame$respondent,'-',d.frame$respondentIndex))
d.frame <- subset(d.frame,d.frame$opposing.parties==1)

####
####Effects of Co-Partisanship and Issue Agreement on Support
####
load("updated.weight.frame.1.RData")
dim(d.frame)
d.frame <- merge(d.frame,updated.weight.frame.1,by.x=c('ResponseId'),by.y=c('caseid'),all.x=TRUE)
dim(d.frame)

#Pooled Overall No. Issue Agreement and Party
all.model.number <- lm(selected~copartisan + factor(number.agreements),data=d.frame)
all.model.number <- fit.w.robust(all.model.number,'respondent',d.frame)

all.model.number.weighted <- lm(selected~copartisan + factor(number.agreements),data=d.frame,weights=d.frame$weights.nes)
all.model.number.weighted <- fit.w.robust(all.model.number.weighted,'respondent',d.frame)

all.model.number.dem <- lm(selected~copartisan + factor(number.agreements),data=d.frame[which(d.frame$dem==1),])
all.model.number.dem <- fit.w.robust(all.model.number.dem,'respondent',d.frame[which(d.frame$dem==1),])

all.model.number.rep <-  lm(selected~copartisan + factor(number.agreements),data=d.frame[which(d.frame$dem==0),])
all.model.number.rep <- fit.w.robust(all.model.number.rep,'respondent',d.frame[which(d.frame$dem==0),])

apsrtable(all.model.number,all.model.number.weighted,all.model.number.dem,all.model.number.rep,model.names=c('All','All - Reweighted','Democrats Only','Republican Only'),coef.names=c('(Intercept)','Co-Partisan','High-Salience Agree - 1 Issue','High-Salience Agree - 2 Issues','High-Salience Agree - 3 Issues','High-Salience Agree - 4 Issues'),caption=c('Effect of Co-Partisanship and Issue Agreement on Candidate Choice - Study 1'))


pdf(file='individualdisagreement-coefficients-study1.pdf')
par(mar=c(4.1,5.75,2,6.75))
plot(y=5:1,x=all.model.number$coefficients[2:6],pch=16,col='black',yaxt='n',ylab='',xlim=c(0,.6),cex=2,xlab='Effect on Pr(Prefer Candidate)',ylim=c(.75,5.25))
segments(y0=5:1,x0=all.model.number$coefficients[2:6]-2*all.model.number$coeftest[2:6,2],x1=all.model.number$coefficients[2:6]+2*all.model.number$coeftest[2:6,2],lwd=4)
abline(h=4.5,lwd=2)
#abline(h=8.5,lwd=2)
axis(side=2,at=5:1,labels=c('Co-Partisan','1 Issue','2 Issues','3 Issues','4 Issues'),las=1)
axis(side=4,at=c(2.5,5),labels=c('Issue Agreement','Partisanship'),las=1,tick=FALSE,line=-.75)
dev.off()

####
###Effect of Party Label Not Conditioning on Issue Agreement (for response memo)
####

only.party <- lm(selected~copartisan, data=d.frame)
only.party <- fit.w.robust(only.party,'respondent',d.frame)
apsrtable(only.party,model.names=c('Shared Party Label'),coef.names=c('(Intercept)','Co-Partisan'),caption=c('Effect of Co-Partisanship on Candidate Choice - Study 1'))


####
####Levels of Support By Reputation Consistency
####

copartisan.reputation <- lm(selected~factor(number.consistent),data=d.frame[which(d.frame$copartisan==1),])
copartisan.reputation <- fit.w.robust(copartisan.reputation,'respondent',d.frame[which(d.frame$copartisan==1),])

outpartisan.reputation <- lm(selected~factor(number.consistent),data=d.frame[which(d.frame$copartisan==0),])
outpartisan.reputation <- fit.w.robust(outpartisan.reputation,'respondent',d.frame[which(d.frame$copartisan==0),])


# # label.by.reputation <- lm(selected~copartisan*factor(number.agreements),data=d.frame)
# label.by.reputation <- fit.w.robust(label.by.reputation,'respondent',d.frame)
# label.by.reputation$coeftest

# label.by.reputation <- lm(selected~factor(number.consistent),data=d.frame[which(d.frame$copartisan==1),])
# label.by.reputation <- fit.w.robust(label.by.reputation,'respondent',d.frame[which(d.frame$copartisan==1),])
# label.by.reputation$coeftest

# label.by.reputation <- lm(selected~copartisan + I(copartisan & number.consistent==1) + I(copartisan & number.consistent==2) + I(copartisan & number.consistent==3) + I(copartisan & number.consistent==4) + I(copartisan & number.consistent==5) + factor(number.agreements),data=d.frame)
# label.by.reputation <- fit.w.robust(label.by.reputation,'respondent',d.frame)
# label.by.reputation$coeftest

# label.by.reputation <- lm(selected~copartisan*factor(number.consistent) + copartisan*factor(number.agreements),data=d.frame)
# label.by.reputation <- fit.w.robust(label.by.reputation,'respondent',d.frame)
# label.by.reputation$coeftest


pdf(file='reputationdisagreement-coefficients-study1.pdf',height=4,width=8)

par(mar=c(4.1,4.5,2,4.75),mfrow=c(1,2))

plot(y=5:1,x=outpartisan.reputation$coefficients[2:6],pch=16,col='black',yaxt='n',ylab='',xlim=c(-.8,.05),cex=2,xlab='Effect on Pr(Prefer Candidate)',ylim=c(0.75,5.25),main='Out-Partisan Candidate',xaxt='n')
segments(y0=5:1,x0=outpartisan.reputation$coefficients[2:6]-2*outpartisan.reputation$coeftest[2:6,2],x1=outpartisan.reputation$coefficients[2:6]+2*outpartisan.reputation$coeftest[2:6,2],lwd=4)
abline(v=0,lty=2)
#abline(h=4.5,lwd=2)
axis(side=2,at=5:1,labels=c('1 Issue','2 Issues','3 Issues','4 Issues','5 Issues'),las=1)
axis(side=4,at=c(3),labels=c('Reputation
Consistent'),las=1,tick=FALSE,line=-.75)
axis(side=1,at=c(-.8,-.6,-0.4,-0.2,0))

plot(y=5:1,x=copartisan.reputation$coefficients[2:6],pch=16,col='black',yaxt='n',ylab='',xlim=c(-.05,.8),cex=2,xlab='Effect on Pr(Prefer Candidate)',ylim=c(0.75,5.25),main='Co-Partisan Candidate',xaxt='n')
segments(y0=5:1,x0=copartisan.reputation$coefficients[2:6]-2*copartisan.reputation$coeftest[2:6,2],x1=copartisan.reputation$coefficients[2:6]+2*copartisan.reputation$coeftest[2:6,2],lwd=4)
abline(v=0,lty=2)
#abline(h=4.5,lwd=2)
axis(side=2,at=5:1,labels=c('1 Issue','2 Issues','3 Issues','4 Issues','5 Issues'),las=1)
axis(side=4,at=c(3),labels=c('Reputation
Consistent'),las=1,tick=FALSE,line=-.75)
axis(side=1,at=c(0,.2,.4,.6,.8))
dev.off()

####
####Levels of Support By Issue Disagreement
####
copartisan.levels <- lm(selected~factor(number.disagreements), data=d.frame[which(d.frame$copartisan==1),])
copartisan.levels <-  fit.w.robust(copartisan.levels,'respondent',d.frame[which(d.frame$copartisan==1),])
copartisan.levels


outpartisan.levels <- lm(selected~factor(number.disagreements), data=d.frame[which(d.frame$copartisan==0),])
outpartisan.levels <- fit.w.robust(outpartisan.levels,'respondent',d.frame[which(d.frame$copartisan==0),])

interact.coefs.coparty <- c(copartisan.levels$coefficients[1],copartisan.levels$coefficients[1] + copartisan.levels$coefficients[2:5])
interact.coefs.outparty <- c(outpartisan.levels$coefficients[1],outpartisan.levels$coefficients[1] + outpartisan.levels$coefficients[2:5])

interact.ses.coparty <- c(sqrt(copartisan.levels$se[1,1]),sapply(X=2:5, FUN=function(x) sqrt(copartisan.levels$se[1,1] + copartisan.levels$se[x,x] + 2*copartisan.levels$se[1,x])))
interact.ses.outparty <- c(sqrt(outpartisan.levels$se[1,1]),sapply(X=2:5, FUN=function(x) sqrt(outpartisan.levels$se[1,1] + outpartisan.levels$se[x,x] + 2*outpartisan.levels$se[1,x])))

pdf(file="individualdisagreement-levels-study1.pdf")
par(mar=c(4,4,2,2))
plot(x=0:4-.1,y=interact.coefs.coparty,pch=16,las=1,ylim=c(0,1),xlab="# Issue Disagreements With Candidate",ylab="Pr(Select Candidate)",xlim=c(-.2,4.2),main="",cex=2.5,type='n')
abline(h=.5,lty=1,lwd=3)
abline(h=.88,lty=2,lwd=3)
abline(h=.12,lty=2,lwd=3,col='gray50')


#lines(x=0:4-.1,y=interact.coefs.coparty,col='black',lty=2,lwd=2)
#lines(x=0:4+.1,y=interact.coefs.outparty,col='gray50',lty=2,lwd=2)
lines(x=0:4-.1,y=interact.coefs.coparty,col='black',lwd=3)
lines(x=0:4+.1,y=interact.coefs.outparty,col='gray50',lwd=3)


points(x=0:4-.1,y=interact.coefs.coparty,pch=16,cex=2.5)
points(x=0:4+.1,y=interact.coefs.outparty,col='gray50',pch=16,cex=2.5)

segments(x0=0:4-.1,y0=interact.coefs.coparty+2*interact.ses.coparty,y1=interact.coefs.coparty-2*interact.ses.coparty,lwd=4)
segments(x0=0:4+.1,y0=interact.coefs.outparty+2*interact.ses.outparty,y1=interact.coefs.outparty-2*interact.ses.outparty,lwd=4,col='gray50')

legend('topright',legend=c('Co-Partisan','Out-Partisan'),col=c('black','gray50'),pch=c(16,16),pt.cex=c(2,2))
#legend('topright',legend=c('Co-Partisan (General)','Out-Partisan (General)'),col=c('black','gray40'),pch=c(16,16))
dev.off()

####
####Effects of Issue Agreement Separated by Issue 
####

issueeffect.byissue <- lm(selected~corporate.tax.agree + muslim.immigration.agree + obamacare.agree + birth.control.agree,data=d.frame)
issueeffect.byissue  <- fit.w.robust(issueeffect.byissue ,'respondent',d.frame)
apsrtable(issueeffect.byissue,coef.names=c('(Intercept)','Corporate Tax','Muslim Immigration','Obamacare','Birth Control'),caption=c('Effect of Issue Agreement on Candidate Choice - Study 1 - By Issue'))

